package com.utils.json;

import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * Created by rain on 2017/3/29.
 */
public class JsonUtils {
    private static ObjectMapper mapper = null;

    private static ObjectMapper getMapper() {
        if (mapper == null) {
            mapper = new ObjectMapper();
            //TODO 这里还需要对mapper配置
        }
        return mapper;
    }

    public static String toJson(Object bean) {
        try {
            return getMapper().writeValueAsString(bean);
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }

}
